//
//  NetworkTools.swift
//  SwiftDemo
//
//  Created by 李国卿 on 2020/1/19.
//  Copyright © 2020 guoqing.li. All rights reserved.
//

import UIKit
import Alamofire

enum MethodType {
    case get
    case post
}
class NetWorkTools {
    class func requestData(type : MethodType,URLString : String,parameters:[String : Any]? = nil,finishCallBack: @escaping (_ result : AnyObject) -> () ){
        
        //1 获取类型
        let method = type == .get ? HTTPMethod.get :HTTPMethod.post;
        
        //2 发起请求
        Alamofire.request(URLString, method: method, parameters: parameters).responseJSON { (response) in
            //3 获取数据
            guard let result = response.result.value else {
                return
            }
            //4 将数据返回
            finishCallBack(result as AnyObject)
        }
    }
}
